package com.gpnu7_412.yanzhi.config;

import com.gpnu7_412.yanzhi.interceptors.LoginInterceptor;
import com.gpnu7_412.yanzhi.interceptors.ManagerInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ZZH
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    @Autowired
    private ManagerInterceptor managerInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> loginExcludeUrls = new ArrayList<>();
        loginExcludeUrls.add("/user/login/*");
        loginExcludeUrls.add("/user/register");
        loginExcludeUrls.add("/verification");
        registry.addInterceptor(loginInterceptor).excludePathPatterns(loginExcludeUrls).order(1);

        List<String> managerIncludeUrls = new ArrayList<>();
        managerIncludeUrls.add("/handing/**");
        managerIncludeUrls.add("/management/**");
        registry.addInterceptor(managerInterceptor).addPathPatterns(managerIncludeUrls).order(2);
    }
}
